var fbNotify = new Object;
fbNotify.visible = false;
fbNotify.options = {
    target: 'main_content',
    type: 'info',
    timeout: 5000
}
fbNotify.showNotify = function (){
    var options = this.options;
    if (typeof(arguments[0]) == 'object'){
        options = this.getOptions(arguments[0]);
    }else if (typeof(arguments[0]) == 'string'){
        options.target = arguments[0];
        if (typeof(arguments[1]) == 'string')
            options.title = arguments[1]; 
        if (typeof(arguments[2]) == 'string')
            options.description = arguments[2];
        if (typeof(arguments[3]) == 'string')
            options.description = arguments[3];
        if (typeof(arguments[4]) == 'string' || typeof(arguments[4]) == 'number')
            options.timeout = arguments[4];
        options = this.getOptions(options);
        
    }
    var currentNotify = $('.fb_notification');
    if (currentNotify.size() > 0){
        currentNotify.animate({height: 0, opacity: 0}, "normal", function(){
            $(currentNotify).remove();
        });
        if (typeof(fbNotify.to) != 'undefined') clearTimeout(fbNotify.to);
    }
    var className;
    switch(options.type){
        case 'info':
            className = 'fb_info';
            break;
        case 'error':
            className = 'fb_error';
            break;
        case 'success':
            className = 'fb_warning';
            break;
    }
    this.container = cE('div', {className:'fb_notification'}, {display: 'none'});
    var text = "<div class='" + className + "'>";
    if (options.title) text += "<div class='title'>" + options.title + "</div>";
    if (options.description) text += "<div class='desc'>" + options.description + "</div></div>";
        this.container.innerHTML = text;
    switch(options.position){
        case 'top':
            $(options.target).prepend(this.container);
            break;
        case 'bottom':
            $(options.target).append(this.container);
        case 'after':
            $(options.target).after(this.container);
            break;
        case 'before':
            $(options.target).before(this.container);
            break;
        default:
            $(options.target).prepend(this.container);
    }
    $(this.container).animate({height: "toggle", opacity: "toggle"}, "fast", function(){
        fbNotify.visible = true;
    });
    if (options.timeout != false) fbNotify.to = setTimeout(function(){fbNotify.hideNotify()}, options.timeout);   
    return true;
}
fbNotify.hideNotify = function (callback){
    if (this.container){
        $(this.container).animate({height: 0, opacity: 0}, "normal", function(){
            $(this.container).remove();
            fbNotify.visible = false;
            if (typeof(callback) == 'function') callback();
        });
        return true;
    }else{
        return false;
    }
}
fbNotify.getOptions = function(options){
    var opt = this.options;
    if (typeof(options) == 'object'){
        opt = extend(this.options, options);
    }
    if (typeof(opt.target) == 'string'){
        if (opt.target.match(/[#\.]/) == null){
            opt.target = '#' + opt.target;
        }
    }
    return opt;
}